package cn.itcast.config;

import com.github.wxpay.sdk.MyConfig;
import com.github.wxpay.sdk.WXPay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

@Configuration
public class WXPayExample {

    @Bean
    public String indentUrl() throws Exception {
        String url = null;
        MyConfig config = new MyConfig();
        WXPay wxpay = new WXPay(config);

        String lUUID = String.format("%040d", new BigInteger(UUID.randomUUID().toString().replace("-", ""), 16));
        String substring = lUUID.substring(19);

        Map<String, String> data = new HashMap<String, String>();

        data.put("appid","wx3bdb1192c22883f3");
        data.put("mch_id","1473426802");
        data.put("nonce_str","5K8264ILTKCH16CQ2502SI8ZNMTM67VS");
        data.put("sign","db9d6b88821df403e5ff11742e799105");
        data.put("body","腾讯充值中心-QQ会员充值");
        data.put("device_info", "");
        data.put("fee_type", "CNY");
        data.put("out_trade_no",substring);
        data.put("total_fee","1");
        data.put("spbill_create_ip","127.0.0.1");
        data.put("notify_url","http://czjk.free.idcfengye.com/pay/statu");
        data.put("trade_type","NATIVE");
        data.put("product_id", "12");


        try {
            Map<String, String> resp = wxpay.unifiedOrder(data);
            System.out.println(resp);
            url = resp.get("code_url");

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("WXPayExample:" + url);
        return url;
    }
}